let express= require("express");
let router= express.Router();
//定义数据模型
/**
 * @swagger
 *  definitions:
 *   studentModel:
 *     properties:
 *       _id: {
 *            type: string,
 *            description: 学生的编号
 *            }
 *       name: {
 *            type: string,
 *            description: 学生的姓名
 *            }
 *       age: {
 *            type: integer,
 *            description: 学生的年龄
 *            }
 *   resultModel:
 *     properties:
 *       code: {
 *            type: integer,
 *            description: 成功 0,失败 1
 *            }
 *       msg: {
 *            type: string,
 *            description: 操作结果的描述
 *            }
 *       datas: {
 *            type: array,
 *            description: 学生的集合,
 *            $ref: '#/definitions/studentModel'
 *            }
 */
//--------------传对象的方式---------
/**
 * @swagger
 * /student:   # 接口的路径url 
 *   get:      # http提交方式
 *     tags:   # 一个标签来做分组显示的
 *       - 学生模块
 *     description: 返回一个结果对象  # 返回类型的描述
 *     produces:
 *       - application/json  # 返回数据类型
 *     responses:
 *       200:
 *         description: 返回操作对象
 *         schema:
 *           $ref: '#/definitions/resultModel'
 *       404: 
 *          description: url地址可能错误
 */
router.get("/",(req,res)=>{

     res.json({"code":0,"msg":"操作成功","datas":[{"_id":1,"name":"张三","age":18},
                                                {"_id":2,"name":"李四","age":20},
                                                {"_id":3,"name":"王五","age":22}
                                                ]})
})


/**
 * @swagger
 * /student/{id}:   # 接口的路径url 
 *   get:      # http提交方式
 *     tags:   # 一个标签来做分组显示的
 *       - 学生模块
 *     description: 查询学生详细信息  # 返回类型的描述
 *     produces:
 *       - application/json  # 返回数据类型
 *     parameters:
 *       - name: id
 *         description: 学生对象id
 *         in: path
 *         required: true
 *         type: string
 *     responses:
 *       200:
 *         description: 返回操作对象
 *         schema:
 *           $ref: '#/definitions/resultModel'
 *       404: 
 *          description: url地址可能错误
 */
router.get("/:id",(req,res)=>{
      
    let {id} = req.params;

    res.json({"code":0,"msg":"查询成功","datas":[{id,"name":"你好","age":20}]});
})

//传的一个对象的方式
/*
 * @swagger
 * /student:
 *   post:
 *     tags:
 *       - 学生模块
 *     description: 添加一个学生
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: stduentObj
 *         description: 学生对象
 *         in: body
 *         required: true
 *         schema:
 *           $ref: '#/definitions/studentModel'
 *     responses:
 *       200:
 *         description: 返回一个操作结果对象
 *         schema:
 *           $ref: '#/definitions/resultModel'
 */
/**
 * @swagger
 * /student:
 *   post:
 *     tags:
 *       - 学生模块
 *     description: 添加一个学生
 *     produces:
 *       - application/json
 *     parameters:
 *        - name: studentId
 *          description: 学生编号
 *          in: query
 *          required: true
 *          type: string
 *        - name: studentName
 *          description: 学生名字
 *          in: query
 *          required: true
 *          type: string
 *        - name: studentAge
 *          description: 学生年龄
 *          in: query
 *          required: true
 *          type: integer
 *     responses:
 *       200:
 *         description: 返回一个操作结果对象
 *         schema:
 *           $ref: '#/definitions/resultModel'
 */
router.post("/",(req,res)=>{
    //let {_id,name,age} = req.body;
    let {studentId,studentName,studentAge} = req.query;
    res.json({"code":0,"msg":"添加成功","datas":[{studentId,studentName,studentAge}]})
})
router.delete("/:id",(req,res)=>{
    let {id} = req.params;
    res.json({"opt":"删除学生的信息"+id});
})
router.put("/",(req,res)=>{
    let {id} = req.params;
    res.json({"opt":"修改学生的信息"+id})
})

module.exports=router;


